export const formatTime = (t) => t ? new Date(t).toLocaleString('zh', { hour12: true }) : '-'

export const parseParams = (data) => {
    try {
        var tempArr = [];
        for (var i in data) {
            var key = encodeURIComponent(i);
            var value = encodeURIComponent(data[i]);
            tempArr.push(key + '=' + value);
        }
        var urlParamsStr = tempArr.join('&');
        return urlParamsStr;
    } catch (err) {
        return '';
    }
}
export const formatCascaderOpts = (res, level, isLastLevel = false) => {
    if (res.length === 0) { return [] }
    res.forEach(v => {
        if (!isLastLevel) {
            v.children = []
        }
        v.level = level
    })
    return res
}
export const getSelectedItemFromOpts = (arr, idArr) => {
    let item = null
    let sub = arr
    for (let index = 0; index < idArr.length; index++) {
        const id = idArr[index];
        item = sub.find(v => v.id == id)
        if (item) {
            sub = item.children
        } else {
            return
        }
    }
    return item
}
export const isDev = process.env.NODE_ENV === 'development'